package com.woniuxy.oldobject.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.oldobject.dao.AddressDao;
import com.woniuxy.oldobject.dao.NightTourDao;
import com.woniuxy.oldobject.dao.StaffDao;
import com.woniuxy.oldobject.dto.NigthtTourDto;
import com.woniuxy.oldobject.entity.NightTour;
import com.woniuxy.oldobject.service.NightTourService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * description: NightTourServiceImpl <br>
 * date: 2022/7/21 2:38 下午 <br>
 * author: shesaifei <br>
 * version: 1.0 <br>
 */
@Service
public class NightTourServiceImpl extends ServiceImpl<NightTourDao, NightTour> implements NightTourService {

    @Autowired
    private NightTourDao nightTourDao;
    @Autowired
    private StaffDao staffDao;
    @Autowired
    private AddressDao addressDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public NightTour queryById(Integer id) {
        return null;
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<NightTour> queryAllByLimit(int offset, int limit) {
        return null;
    }

    /**
     * 新增数据
     *
     * @param nightTour 实例对象
     * @return 实例对象
     */
    @Override
    public int inserts(NigthtTourDto nightTour) {
        List<Integer> workerIds = nightTour.getWorkerIds();
        ArrayList<NightTour> list = new ArrayList<>();
        Integer placeId = nightTour.getPlaceId();
        Date patrolTime = nightTour.getPatrolTime();
        String place = nightTour.getPlace();
        List<String> workerNames = nightTour.getWorkerNames();
        int index = 0;
        for (Integer workerId : workerIds) {
            NightTour nightTour1 = new NightTour();
            nightTour1.setPlaceId(placeId);
            nightTour1.setPlace(place);
            nightTour1.setPatrolTime(patrolTime);
            nightTour1.setWorkerId(workerId);
            nightTour1.setWorkerName(workerNames.get(index++));
            list.add(nightTour1);
        }
        return nightTourDao.inserts(list);
    }

    /**
     * 修改数据
     *
     * @param nightTour 实例对象
     * @return 实例对象
     */
    @Override
    public int update(NightTour nightTour) {
        int i = nightTourDao.update(nightTour);
        return i;
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public int deleteById(Integer id) {
        int i = nightTourDao.deleteById(id);
        return i;
    }

    /**
     * 通过实体作为筛选条件查询
     *
     * @param nigthtTour@return 对象列表
     */
    @Override
    public List<NightTour> queryAll(NigthtTourDto nigthtTour) {
        return nightTourDao.queryAll(nigthtTour);
    }
}
